package com.cxy.jdk_proxy;

import java.lang.reflect.Proxy;

public class ProxyFactory {

    TrainStation trainStation = new TrainStation();

    /**
     * @Author 会飞的企鹅
     * @Description TODO
     * @Date 2024/11/2 16:00
     */
    public SellTickets getProxyObject(){
        SellTickets sellTickets = (SellTickets)Proxy.newProxyInstance(
                trainStation.getClass().getClassLoader(),
                trainStation.getClass().getInterfaces(),
                (proxy,method,args)->{
                    System.out.println("代理收取费用(jdk代理)");
                    Object invoke = method.invoke(trainStation, args);
                    return invoke;
                }
        );
        return sellTickets;
    }
}
